home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libiconv_src.lha / src / isoir165.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-07  |  4.6 KB  |  134 lines

  1. /*
  2.  * ISO-IR-165
  3.  */
  4.  
  5. /*
  6.  * ISO-IR-165 is an extension of GB 2312, consisting of:
  7.  * 1. GB 6345.1-86 corrections:
  8.  *    Two corrections to GB 2312, at 0x2367 and 0x6F71.
  9.  * 2. GB 6345.1-86 additions:
  10.  *    - 6 new full-width pinyin characters in row 0x28.
  11.  *    - ISO646-CN in row 0x2A.
  12.  *    - 32 half-width pinyin characters in row 0x2B.
  13.  * 3. GB 8565.2-88 additions:
  14.  *    - 50 characters in row 0x2D.
  15.  *    - 92 characters in row 0x2E.
  16.  *    - 93 characters in row 0x2F.
  17.  *    - 470 characters in rows 0x7A-0x7E.
  18.  * 4. ISO-IR-165 additions:
  19.  *    - 22 characters in row 0x26.
  20.  *    - 94 characters in row 0x2C.
  21.  *    - 44 new characters in row 0x2D.
  22.  *    - 1 new character in row 0x2F.
  23.  *
  24.  * The conversion table was created from the following sources:
  25.  * Ad 1. The 0x2367 correction is already integrated in the unicode.org
  26.  *       GB2312.TXT table. The 0x6F71 mapping is the same in the unicode.org
  27.  *       GB2312.TXT and UNIHAN.TXT table and in Koichi Yasuoka's Uni2GB table,
  28.  *       so we assume it's correct.
  29.  * The unicode.org UNIHAN.TXT table about GB 8565 is not usable: it has
  30.  * extraneous code points at rows 0x28, 0x2C, 0x2D. Note also that it does
  31.  * not list the 69 non-hanzi in row 0x2F. Moreover, it has the characters
  32.  * 0x2F7A-0x2F7D shifted down by one to 0x2F79-0x2F7C.
  33.  * Therefore we take the GB8565 and ISO-IR-165 data from Koichi Yasuoka's
  34.  * Uni2GB table.
  35.  * Ad 1. Yasuoka maps 0x2367 to U+0261 (small script g) and 0x2840 to U+FF47
  36.  *       (full-width small normal g). While coherent with ISO-IR's 165.pdf,
  37.  *       this disagrees with Ken Lunde's book: He says that ISO-IR-165
  38.  *       includes the GB6345 correction, i.e. maps 0x2367 to U+FF47 or U+0067
  39.  *       and _not_ to U+0261 (small script g).
  40.  *       To overcome the confusion, we just map both 0x2367 and 0x2840 to
  41.  *       U+FF47.
  42.  * Ad 2. Row 0x28: Add a mapping from 0x283F to U+01F9.
  43.  *       Row 0x2A: Mapping is well-known, also present in Koichi Yasuoka's
  44.  *                 table.
  45.  *       Row 0x2B: Typed in by hand from appendix E in Ken Lunde's book.
  46.  *       When converting from Unicode to ISO-IR-165, prefer the half-width
  47.  *       range 0x2B{21..40} to the full-width range 0x28{21..40}.
  48.  * Ad 3. Rows 0x2D, 0x2E: Both Koichi Yasuoka's Uni2GB table and the UNIHAN.TXT
  49.  *                 data for GB 8565 agree here.
  50.  *       Row 0x2F: Taken from Koichi Yasuoka's Uni2GB table.
  51.  *       Rows 0x7A-0x7E: Koichi Yasuoka's Uni2GB table and the UNIHAN.TXT
  52.  *                 data for GB 8565 agree here mostly. Differences:
  53.  *                 0x7C38 -> U+6F26 or U+527A ? We choose U+6F26.
  54.  *                 0x7C5A -> U+7A40 or U+6996 ? We choose U+6996.
  55.  * Ad 4. Row 0x26: Mapping unknown.
  56.  *       Rows 0x2C, 0x2D: Both Koichi Yasuoka's Uni2GB table and the UNIHAN.TXT
  57.  *                 data for GB 8565 (!) agree here.
  58.  *       Row 0x2F: Taken from Koichi Yasuoka's Uni2GB table.
  59.  */
  60.  
  61. #include "isoir165ext.h"
  62.  
  63. static int
  64. isoir165_mbtowc (conv_t conv, wchar_t *pwc, const unsigned char *s, int n)
  65. {
  66.   int ret;
  67.  
  68.   /* Map full-width pinyin (row 0x28) like half-width pinyin (row 0x2B). */
  69.   if (s[0] == 0x28) {
  70.     if (n >= 2) {
  71.       unsigned char c2 = s[1];
  72.       if (c2 >= 0x21 && c2 <= 0x40) {
  73.         unsigned char buf[2];
  74.         buf[0] = 0x2b;
  75.         buf[1] = c2;
  76.         ret = isoir165ext_mbtowc(conv,pwc,buf,2);
  77.         if (ret != RET_ILSEQ)
  78.           return ret;
  79.       }
  80.     }
  81.   }
  82.   /* Try the GB2312 -> Unicode table. */
  83.   ret = gb2312_mbtowc(conv,pwc,s,n);
  84.   if (ret != RET_ILSEQ)
  85.     return ret;
  86.   /* Row 0x2A is GB_1988-80. */
  87.   if (s[0] == 0x2a) {
  88.     if (n >= 2) {
  89.       unsigned char c2 = s[1];
  90.       if (c2 >= 0x21 && c2 < 0x7f) {
  91.         int ret = iso646_cn_mbtowc(conv,pwc,s+1,1);
  92.         if (ret != 1) abort();
  93.         return 2;
  94.       }
  95.       return RET_ILSEQ;
  96.     }
  97.     return RET_TOOFEW(0);
  98.   }
  99.   /* Try the ISO-IR-165 extensions -> Unicode table. */
  100.   ret = isoir165ext_mbtowc(conv,pwc,s,n);
  101.   return ret;
  102. }
  103.  
  104. static int
  105. isoir165_wctomb (conv_t conv, unsigned char *r, wchar_t wc, int n)
  106. {
  107.   unsigned char buf[1];
  108.   int ret;
  109.  
  110.   /* Try the Unicode -> GB2312 table table. */
  111.   ret = gb2312_wctomb(conv,r,wc,n);
  112.   if (ret != RET_ILSEQ) {
  113.     if (ret != 2) abort();
  114.     if (!(r[0] == 0x28 && r[1] >= 0x21 && r[1] <= 0x40))
  115.       return ret;
  116.   }
  117.   /* Row 0x2A is GB_1988-80. */
  118.   ret = iso646_cn_wctomb(conv,buf,wc,1);
  119.   if (ret != RET_ILSEQ) {
  120.     if (ret != 1) abort();
  121.     if (buf[0] >= 0x21 && buf[0] < 0x7f) {
  122.       if (n >= 2) {
  123.         r[0] = 0x2a;
  124.         r[1] = buf[0];
  125.         return 2;
  126.       }
  127.       return RET_TOOSMALL;
  128.     }
  129.   }
  130.   /* Try the Unicode -> ISO-IR-165 extensions table. */
  131.   ret = isoir165ext_wctomb(conv,r,wc,n);
  132.   return ret;
  133. }
  134.